import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import '@/api/mock'
import Cookies from 'js-cookie'

// import { Container, Header, Main, Aside } from 'element-ui';
// Vue.use(Container).use(Header).use(Main).use(Aside);

import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';

Vue.use(ElementUI);

router.beforeEach((to, from, next) => {
  // 
  const token = Cookies.get('token');
  if (!token && to.name !== 'login') {
    next({ name: 'login' })
  } else if (token && to.name == 'login') {
    next({ name: 'home' })
  } else[
    next()
  ]
})


Vue.config.productionTip = false

new Vue({
  router,
  store,
  render: h => h(App),
  created() {
    store.commit('tag/addMenu', router)
  }
}).$mount('#app')
